package map;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

public class HashMapTest {

    public static void main(String[] args) {
        HashMap<Integer, String> map = new HashMap<>();
        map.put(1, "A");
        map.computeIfAbsent(2, Integer::toUnsignedString);
        System.out.println(map.get(2));
        List<String> list = new ArrayList<>();
        list.add("111");
        list.add("222");
        list.add("333");
        list.forEach(System.out::println);
        List<Integer> list2 = list.stream().map(Integer::valueOf).collect(Collectors.toList());
        System.out.println(list2.size());

        HashMap<Key, Value> map2 = new HashMap<>();
        map2.computeIfAbsent(new Key(5), Key::getDefaultV);
        System.out.println(map2.get(new Key(5)));
        
        List<String> testData = new ArrayList<String>();
        testData.add("张三");
        testData.add("李四");
        testData.add("张武");
        testData.add("麻子");
        List<String> filter = testData.stream().filter(x -> x.startsWith("张")).collect(Collectors.toList());
        for (String string : filter) {
            System.out.println(string);
        }
    }

    public static String sayValue() {
        return "B";
    }

    public void b() {
        
    }
    
    public void a() {
        List<String> list = new ArrayList<>();
        list.add("111");
        list.add("222");
        list.add("333");
        
        
        HashMap<Key, Value> map2 = new HashMap<>();
        
        map2.computeIfAbsent(new Key(1), Key::getDefaultV);
        System.out.println(map2.get(new Key(1)));
    }

}
class Key {
    int a;
    public Key(int a) {
        this.a = a;
    }
    public Key() {
    }
    int getA() {
        return a;
    }
    public Value getDefaultV() {
        return new Value(this.getA()+":default");
    }
    @Override
    public int hashCode() {
        return a;
    }
    @Override
    public boolean equals(Object obj) {
        return this.hashCode() == obj.hashCode();
    }
    @Override
    public String toString() {
        return "oooooooo";
    }
    
    
}
class Value {
    String value;
    public Value() {
    }
    public Value(String value) {
        this.value = value;
    }
    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("Value [value=");
        builder.append(value);
        builder.append("]");
        return builder.toString();
    }
    public static Value createValue(Key key) {
        return new Value(key.getA() + ":default");
    }
}
